<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: nz::nodes::calc::Img2ColNode Class Reference</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>nz</b></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes.html">nodes</a></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes_1_1calc.html">calc</a></li><li class="navelem"><a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html">Img2ColNode</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classnz_1_1nodes_1_1calc_1_1_img2_col_node-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">nz::nodes::calc::Img2ColNode Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Implements im2col transformation for efficient convolution operations in neural networks.  
 <a href="#details">More...</a></p>
<div class="dynheader">
Inheritance diagram for nz::nodes::calc::Img2ColNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_img2_col_node__inherit__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_img2_col_node_inherit__map" alt="Inheritance graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_img2_col_node_inherit__map" id="anz_1_1nodes_1_1calc_1_1_img2_col_node_inherit__map">
<area shape="rect" title="Implements im2col transformation for efficient convolution operations in neural networks." alt="" coords="5,80,204,107"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="46,5,163,32"/>
<area shape="poly" title=" " alt="" coords="107,48,107,80,102,80,102,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for nz::nodes::calc::Img2ColNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_img2_col_node__coll__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_img2_col_node_coll__map" alt="Collaboration graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_img2_col_node_coll__map" id="anz_1_1nodes_1_1calc_1_1_img2_col_node_coll__map">
<area shape="rect" title="Implements im2col transformation for efficient convolution operations in neural networks." alt="" coords="5,80,204,107"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="46,5,163,32"/>
<area shape="poly" title=" " alt="" coords="107,48,107,80,102,80,102,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a900bfad8e2c2706ffc9cf5cf20dee6dd" id="r_a900bfad8e2c2706ffc9cf5cf20dee6dd"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a900bfad8e2c2706ffc9cf5cf20dee6dd">Img2ColNode</a> (<a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *input, Tensor::size_type kernelHeight, Tensor::size_type kernelWidth, Tensor::size_type stride, Tensor::size_type padding)</td></tr>
<tr class="memdesc:a900bfad8e2c2706ffc9cf5cf20dee6dd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructor for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a> class.  <br /></td></tr>
<tr class="separator:a900bfad8e2c2706ffc9cf5cf20dee6dd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a199c6e1750035b8b9b4489de664b3ad3" id="r_a199c6e1750035b8b9b4489de664b3ad3"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a199c6e1750035b8b9b4489de664b3ad3">forward</a> () override</td></tr>
<tr class="memdesc:a199c6e1750035b8b9b4489de664b3ad3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs the forward propagation for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a>.  <br /></td></tr>
<tr class="separator:a199c6e1750035b8b9b4489de664b3ad3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a905c98a496d0106aed9af4e71205f653" id="r_a905c98a496d0106aed9af4e71205f653"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a905c98a496d0106aed9af4e71205f653">backward</a> () override</td></tr>
<tr class="memdesc:a905c98a496d0106aed9af4e71205f653"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs the backward propagation for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a>.  <br /></td></tr>
<tr class="separator:a905c98a496d0106aed9af4e71205f653"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="inherit_header pub_methods_classnz_1_1nodes_1_1_node"><td colspan="2" onclick="javascript:dynsection.toggleInherit('pub_methods_classnz_1_1nodes_1_1_node')"><img src="closed.png" alt="-"/>&#160;Public Member Functions inherited from <a class="el" href="classnz_1_1nodes_1_1_node.html">nz::nodes::Node</a></td></tr>
<tr class="memitem:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a687ee9c34eb61f8f28caa201ca42696e"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a687ee9c34eb61f8f28caa201ca42696e">print</a> (std::ostream &amp;os) const</td></tr>
<tr class="memdesc:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Prints the type, data, and gradient of the node.  <br /></td></tr>
<tr class="separator:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a9b85913e12422bb4ac2fff483427bb47"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a9b85913e12422bb4ac2fff483427bb47">dataInject</a> (Tensor::value_type *data, bool grad=false) const</td></tr>
<tr class="memdesc:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data into a relevant tensor object, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a609f1730085dd1d31e0ddcbbae48a065"><td class="memTemplParams" colspan="2">template&lt;typename Iterator &gt; </td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a609f1730085dd1d31e0ddcbbae48a065">dataInject</a> (Iterator begin, Iterator end, const bool grad=false) const</td></tr>
<tr class="memdesc:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from an iterator range into the output tensor of the InputNode, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_af8b4bab3271df92ca1f0914f7a97b1e8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#af8b4bab3271df92ca1f0914f7a97b1e8">dataInject</a> (const std::initializer_list&lt; Tensor::value_type &gt; &amp;data, bool grad=false) const</td></tr>
<tr class="memdesc:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from a std::initializer_list into the output tensor of the <a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a>, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Implements im2col transformation for efficient convolution operations in neural networks. </p>
<p>This node converts (N, C, H, W) input tensors into expanded column matrices (N, 1, Hout*Wout, C*K_h*K_w) following the im2col algorithm, enabling efficient convolution computation through matrix multiplication.</p>
<p>Core functionality and characteristics:</p><ul>
<li><b>Convolution Optimization</b>: Unfilters image patches into column matrices for accelerated convolution computation.</li>
<li><b>Parameterized Transformation</b>: Supports configurable kernel dimensions, stride, and padding.</li>
<li><b>Memory Layout Conversion</b>: Reorganizes spatial data into channel-patch columns.</li>
<li><b>Gradient Propagation</b>: Implements inverse col2im operation during backward pass for gradient computation.</li>
<li><b>CUDA Acceleration</b>: Optimized GPU implementation for both forward and backward operations.</li>
<li><b>Automatic Shape Calculation</b>: Computes output spatial dimensions based on input parameters.</li>
</ul>
<p>Key implementation aspects:</p><ul>
<li><b>Forward Pass</b>: Applies im2col algorithm with zero-padding and window sliding based on parameters.</li>
<li><b>Backward Pass</b>: Accumulates gradients using col2im inverse transformation with proper kernel alignment.</li>
<li><b>Memory Access Patterns</b>: Optimizes for contiguous memory access in transformed column matrices.</li>
<li><b>Parameter Validation</b>: Verifies kernel dimensions don't exceed padded input size.</li>
</ul>
<p>Typical use cases:</p><ul>
<li>Accelerating convolutional layer computations through matrix multiplication.</li>
<li>Implementing custom filter operations requiring explicit patch extraction.</li>
<li>Converting spatial correlations into channel-wise operations.</li>
<li>Data augmentation through explicit patch sampling.</li>
</ul>
<p>Critical considerations:</p><ul>
<li><b>Memory Overhead</b>: Generates O(K_h*K_w*C*Hout*Wout) intermediate storage - may require substantial memory.</li>
<li><b>Parameter Compatibility</b>: Requires (H + 2*padding - K_h) divisible by stride (similar for width).</li>
<li><b>Input Constraints</b>: Strict 4D input tensor requirement (NCHW format).</li>
<li><b>Device Consistency</b>: Maintains original tensor device context (CPU/GPU).</li>
</ul>
<dl class="section warning"><dt>Warning</dt><dd><ul>
<li>Excessive kernel sizes or small strides may create prohibitively large intermediate matrices.</li>
<li>Improper padding/stride combinations may cause dimension calculation errors.</li>
</ul>
</dd></dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Output dimensions follow: Hout = (H + 2*padding - K_h)/stride + 1</li>
<li>The inverse col2im operation in backward pass sums gradients across overlapping patches.</li>
<li>For dilated convolutions, consider extending kernel parameters with dilation factors.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd>ConvolutionNode For typical subsequent operation after im2col transformation </dd>
<dd>
Tensor::im2col() Underlying tensor transformation implementation</dd></dl>
<h3><a class="anchor" id="autotoc_md107"></a>
Usage Example:</h3>
<div class="fragment"><div class="line"><span class="comment">// Create input node with batch of 32 RGB images (256x256)</span></div>
<div class="line">InputNode input({32, 3, 256, 256}, <span class="keyword">true</span>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Configure im2col with 7x7 kernel, stride 2, padding 3</span></div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html">Img2ColNode</a> im2col(&amp;input, 7, 7, 2, 3);</div>
<div class="line">im2col.forward();</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Resulting shape: (32, 1, 128*128, 3*7*7)</span></div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;Transformed shape: &quot;</span> &lt;&lt; im2col.output-&gt;shape() &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Backward pass through col2im</span></div>
<div class="line">im2col.backward();</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_img2_col_node_html"><div class="ttname"><a href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html">nz::nodes::calc::Img2ColNode</a></div><div class="ttdoc">Implements im2col transformation for efficient convolution operations in neural networks.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cuh_source.html#l03729">Nodes.cuh:3729</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2023/10/17 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cuh_source.html#l03729">3729</a> of file <a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a900bfad8e2c2706ffc9cf5cf20dee6dd" name="a900bfad8e2c2706ffc9cf5cf20dee6dd"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a900bfad8e2c2706ffc9cf5cf20dee6dd">&#9670;&#160;</a></span>Img2ColNode()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">nz::nodes::calc::Img2ColNode::Img2ColNode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *</td>          <td class="paramname"><span class="paramname"><em>input</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::size_type</td>          <td class="paramname"><span class="paramname"><em>kernelHeight</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::size_type</td>          <td class="paramname"><span class="paramname"><em>kernelWidth</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::size_type</td>          <td class="paramname"><span class="paramname"><em>stride</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::size_type</td>          <td class="paramname"><span class="paramname"><em>padding</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Constructor for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a> class. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">input</td><td>A pointer to the input <a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a>. Memory location: host. This is a pointer to an existing <a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a> object, and the constructor only stores the pointer, not making a copy of the object. </td></tr>
    <tr><td class="paramname">kernelHeight</td><td>The height of the kernel. Memory location: host. It is a value passed by value, and the constructor stores its copy. </td></tr>
    <tr><td class="paramname">kernelWidth</td><td>The width of the kernel. Memory location: host. It is a value passed by value, and the constructor stores its copy. </td></tr>
    <tr><td class="paramname">stride</td><td>The stride value for the convolution operation. Memory location: host. It is a value passed by value, and the constructor stores its copy. </td></tr>
    <tr><td class="paramname">padding</td><td>The padding value for the convolution operation. Memory location: host. It is a value passed by value, and the constructor stores its copy.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>This constructor initializes an <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a> object. It stores the input node pointer, sets the kernel height, width, stride, and padding values. It also calculates the output height and width based on the input tensor's shape, kernel size, stride, and padding. Then, it creates a new Tensor object for the output with the appropriate shape and gradient requirement. Finally, it sets the node type to "Img2Col".</p>
<p>Memory management strategy: The constructor creates a new Tensor object using <code>std::make_shared</code>, which manages the memory automatically. The input node pointer is just stored, and no new memory is allocated for it. Exception handling mechanism: There is no explicit exception handling in this constructor. However, if the <code>std::make_shared</code> call fails to allocate memory for the output Tensor, a <code>std::bad_alloc</code> exception will be thrown.</p>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">std::bad_alloc</td><td>If memory allocation for the output Tensor fails.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the input node pointer is valid and points to a properly initialized <a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a> object.</li>
<li>The calculation of output height and width assumes valid values for kernel size, stride, and padding. Incorrect values may lead to unexpected results.</li>
<li>The time complexity of the constructor is O(1) as all operations are constant time operations.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>* inputNode = <span class="keyword">new</span> <a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>();</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html">Img2ColNode</a> img2ColNode(inputNode, 3, 3, 1, 1);</div>
<div class="line">```</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1_node_html"><div class="ttname"><a href="classnz_1_1nodes_1_1_node.html">nz::nodes::Node</a></div><div class="ttdoc">Base class for nodes in a neural network or computational graph.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cuh_source.html#l00114">Nodes.cuh:114</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/07/15 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00605">605</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a905c98a496d0106aed9af4e71205f653" name="a905c98a496d0106aed9af4e71205f653"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a905c98a496d0106aed9af4e71205f653">&#9670;&#160;</a></span>backward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::Img2ColNode::backward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Performs the backward propagation for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a>. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">None</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>This function conducts the backward propagation of the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a>. It first checks if the output of the input node requires gradient computation. If so, it calls the <code>iImg2colBackward</code> function, passing in relevant parameters including the gradient of the input node's output, the gradient of the current node's output, output height, output width, the number of input channels, kernel height, kernel width, stride, padding, input height, input width, and batch size. The <code>iImg2colBackward</code> function is responsible for calculating the gradients with respect to the input.</p>
<p>Memory management strategy: The function does not allocate or free any memory directly. It relies on the pre - allocated memory for the gradients of the input and output tensors. The <code>iImg2colBackward</code> function is assumed to write the calculated gradients into the pre - allocated gradient tensors. Exception handling mechanism: There is no explicit exception handling in this function. However, if the <code>iImg2colBackward</code> function encounters problems such as invalid pointers or incorrect input parameters, it may throw an exception.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the gradient tensors of the input and output are properly initialized and have sufficient memory allocated before calling this function.</li>
<li>The performance of this function depends on the implementation of the <code>iImg2colBackward</code> function. Generally, the time complexity of the <code>iImg2colBackward</code> operation is O(n), where n is the number of elements in the input gradient tensor.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html">Img2ColNode</a> img2ColNode; <span class="comment">// Assume img2ColNode is properly initialized</span></div>
<div class="line">img2ColNode.<a class="code hl_function" href="#a905c98a496d0106aed9af4e71205f653">backward</a>();</div>
<div class="line">```</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_img2_col_node_html_a905c98a496d0106aed9af4e71205f653"><div class="ttname"><a href="#a905c98a496d0106aed9af4e71205f653">nz::nodes::calc::Img2ColNode::backward</a></div><div class="ttdeci">void backward() override</div><div class="ttdoc">Performs the backward propagation for the Img2ColNode.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cu_source.html#l00632">Nodes.cu:632</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/07/15 </dd></dl>

<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a0a9ecbaa3d790ba38e8218aca7837fd0">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00632">632</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<a id="a199c6e1750035b8b9b4489de664b3ad3" name="a199c6e1750035b8b9b4489de664b3ad3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a199c6e1750035b8b9b4489de664b3ad3">&#9670;&#160;</a></span>forward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::Img2ColNode::forward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Performs the forward propagation for the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a>. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">None</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>This function executes the forward propagation of the <a class="el" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html" title="Implements im2col transformation for efficient convolution operations in neural networks.">Img2ColNode</a>. It calls the <code>iImg2col</code> function, passing in the necessary parameters such as the output data pointer, input data pointer, output height, output width, number of input channels, kernel height, kernel width, stride, padding, input height, input width, and batch size. The <code>iImg2col</code> function is responsible for converting the image data into a column - major format, which is useful for performing convolution operations more efficiently.</p>
<p>Memory management strategy: The function does not allocate or free any memory directly. It relies on the memory already allocated for the input and output tensors. The <code>iImg2col</code> function is assumed to write the results directly into the pre - allocated output tensor. Exception handling mechanism: There is no explicit exception handling in this function. However, if the <code>iImg2col</code> function encounters issues such as invalid pointers or incorrect input parameters, it may throw an exception.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the input and output tensors are properly initialized and have sufficient memory allocated before calling this function.</li>
<li>The performance of this function depends on the implementation of the <code>iImg2col</code> function. In general, the time complexity of the <code>iImg2col</code> operation is O(n), where n is the number of elements in the output tensor.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_img2_col_node.html">Img2ColNode</a> img2ColNode; <span class="comment">// Assume img2ColNode is properly initialized</span></div>
<div class="line">img2ColNode.<a class="code hl_function" href="#a199c6e1750035b8b9b4489de664b3ad3">forward</a>();</div>
<div class="line">```</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_img2_col_node_html_a199c6e1750035b8b9b4489de664b3ad3"><div class="ttname"><a href="#a199c6e1750035b8b9b4489de664b3ad3">nz::nodes::calc::Img2ColNode::forward</a></div><div class="ttdeci">void forward() override</div><div class="ttdoc">Performs the forward propagation for the Img2ColNode.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cu_source.html#l00624">Nodes.cu:624</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/07/15 </dd></dl>

<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a8a828c2e91a4aa2a9ab7b94554e4685b">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00624">624</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/include/NeuZephyr/<a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a></li>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/src/<a class="el" href="_nodes_8cu_source.html">Nodes.cu</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
